﻿using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.WebTesting;

namespace QA.TFS.Plugins.Request
{
    public class RemoveBadDependantRequest : WebTestRequestPlugin
    {

        private string _BadRequestName = string.Empty;
        public string BadRequestName
        {
            get { return _BadRequestName; }
            set { _BadRequestName = value; }
        }

        public override void PostRequest(object sender, PostRequestEventArgs e)
        {
            base.PostRequest(sender, e);

            if (e.Request.HasDependentRequests)
            {
                List<WebTestRequest> remove = new List<WebTestRequest>();
                foreach (WebTestRequest dependent in e.Request.DependentRequests)
                {
                    if (dependent.Url.EndsWith("/" + BadRequestName))
                        remove.Add(dependent);
                }

                foreach (WebTestRequest dependent in remove)
                    e.Request.DependentRequests.Remove(dependent);
            }
        }

    }

}
